// JavaScript Document
function getOS(){//判断浏览器类型
   if(navigator.userAgent.indexOf("MSIE")>0) {
        return "MSIE"; //IE8
   }
   if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){
        return "Firefox";//火狐
   }
   if(isSafari=navigator.userAgent.indexOf("Safari")>0) {
        return "Safari";//google
   } 
   if(isCamino=navigator.userAgent.indexOf("Camino")>0){
        return "Camino";
   }
   if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){
        return "Gecko";
   }
}
$(document).ready(function(e) {
	var rnd = Math.ceil(Math.random() * 10) % 4;
    var imgbg = 'url(images/rain' + rnd.toString() + '_bg.jpg)';
    var imgcnt = 'url(images/rain' + rnd.toString() + '_cnt.jpg)';
    $('#bd').css("background-image", imgbg);
    $('#bd').css("background-repeat", "repeat-x");
    $('#bd .main-wrap').css("background-image", imgcnt);
    $('#bd .main-wrap').css("background-repeat", "no-repeat");
    $('#bd .main-wrap').css("background-position", "center top");
	
	var userstr=$('#userInt').val();
	var pwd=$('#pwdInt').val();
	var eventkind = getOS() == 'MSIE' ? 'propertychange' : 'input'; //得到事件的类型
	$('#userInt').bind(eventkind,function(){
        if ($('#userInt').val() != '')
        {
            $('#lbluser').css('visibility', 'hidden');
        }
        else
        {
            $('#lbluser').css('visibility', 'visible');
        }
	});
	
	$('#pwdInt').bind(eventkind,function(){
		if($('#pwdInt').val()!='')
		{
			$('#lblpwd').css('visibility', 'hidden');
		}
		else 
		{
			$('#lblpwd').css('visibility', 'visible');
		}
	});
	
	$('#btnLogin').click(function(e) {
		var user=$('#userInt').val();
        var pwd=$('#pwdInt').val();
        $.get('login.ashx',{user:user,pwd:pwd,rnd:Math.random()},function (data)
        {
            if (data == 1)
            {
                window.location.href = "main.aspx";
            }
            else
            {
                alert('用户名或者密码错误，请重新输入');
            }
        });
    });
	
	$('body').keydown(function(e) {
        if (e.keyCode == 13)
        {
            var user = $('#userInt').val();
            var pwd = $('#pwdInt').val();
			$.get('login.ashx',{user:user,pwd:pwd,rnd:Math.random()},function (data)
			{
            	if (data == 1)
            	{
                	window.location.href = "main.aspx";
            	}
            	else
            	{
                	alert('用户名或者密码错误，请重新输入');
            	}
        	});
        }
    });
});